home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Image and Contour Plots / CopyImageSubset < prev    next >
Text File  |  1996-01-29  |  2KB  |  68 lines

  1. // CopyImageSubset
  2. // copies a subrange of an image displayed in an image plot.
  3. // To use, drag out a marquee in an image plot, click within the marquee,
  4. //  and choose "CopyImageSubset" from the popup menu that appears.
  5.  
  6. #include <Strings as Lists>
  7. #include <Keyword-Value>
  8. #include <Graph Utility Procs> version >= 1.2
  9.  
  10. Proc CopyImageSubset() : GraphMarquee
  11.     Silent 1;PauseUpdate
  12.     String list= ImageNameList("",";")
  13.     if( strlen(GetStrFromList(list, 1, ";")) )    // two or more images, comment this test out to make it work with the first of several images
  14.         Abort "CopyImageSubset works only with a single image in a graph"
  15.     endif
  16.     String imagePlot = GetStrFromList(list, 0, ";")
  17.     if (strlen(imagePlot))    // one image
  18.         String info,vaxis,haxis,image,df,xwave,ywave
  19.         Variable i
  20.         info=ImageInfo("",imagePlot,0)
  21.         vaxis=StrByKey("YAXIS",info)
  22.         haxis=StrByKey("XAXIS",info)
  23.         image=StrByKey("ZWAVE",info)
  24.         df=StrByKey("ZWAVEDF",info)
  25.         xwave=StrByKey("XWAVE",info)
  26.         ywave=StrByKey("YWAVE",info)
  27.         if( strlen(xwave)+strlen(ywave) )
  28.             Abort "CopyImageSubset does not work on images with X or Y waves"
  29.         endif
  30.         string modInfo=StrByKey("RECREATION",info)
  31.         info= AxisInfo("",haxis)
  32.         String axisFlags= StrByKey("AXFLAG",info)
  33.         info= AxisInfo("",vaxis)
  34.         axisFlags+=StrByKey("AXFLAG",info)
  35.         String winStyle= WinRecreation("",1)
  36.         Variable swapxy= strsearch(winStyle,"swapXY=1",0) >= 0
  37.         GetMarquee/K $haxis,$vaxis
  38.         if( V_Flag != 1)
  39.             Abort "CopyImageSubset() requires a marquee in the target graph"
  40.         endif
  41.         // copy the marqueed image subset into a clean, liberal, unique name.
  42.         String copy=UniqueName(CleanupName(image+"Copy",1),1,0)
  43.         CopyMatrix(df+image,copy,V_left,V_right,V_top,V_bottom,swapxy)
  44.         // make a graph just like the source graph
  45.         copy= PossiblyQuoteName(copy)    // always use PossiblyQuoteName with Execute
  46.         Preferences 1
  47.         Display;Execute "AppendImage"+axisFlags+" "+copy
  48.         if( strlen(modInfo) )
  49.             Execute "ModifyImage "+copy+" "+modInfo
  50.         endif
  51.         ApplyStyleMacro(winStyle)
  52.         TextBox/E/A=MT "\{ImageNameList(\""+WinName(0,1)+"\",\" \")}"
  53.     else    // no images
  54.         Abort "No Image in graph"
  55.     endif
  56. End
  57.  
  58.  
  59. Proc CopyMatrix(inmatrix,outmatrix,left,right,top,bottom,swapxy)
  60.     String inmatrix,outmatrix
  61.     Variable left,right,top,bottom,swapxy
  62.     
  63.     if( swapxy )
  64.         Duplicate/O/R=(bottom,top)(left,right) $inmatrix,$outmatrix
  65.     else
  66.         Duplicate/O/R=(left,right)(bottom,top) $inmatrix,$outmatrix
  67.     endif
  68. End